//CS1.1

var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}
//-----------------------------------------------------------------------------------------------------------

function refreshFrame(frame){
	frame.location=frame.location;
}

function openUrlMenu(url){
	
	var bar ="toolbar=yes,status=no,menubar=yes,scrollbars=yes,resizable=no,top=0,left=0,width=" + (screen.availWidth-3)  + " height=" + (screen.availHeight-25);
		
	window.open(url,'',bar);
	return false;	
}	

function RovesciaData(Datamia)
{
   var wkdata = "";
   wkdata = Datamia.substr(6, 4) + Datamia.substr(3,2) + Datamia.substr(0,2);
   	return wkdata;
}

function trim(inputString) {
  
   if (typeof inputString != "string") { return inputString; }
  
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   
   ch = retValue.substring(retValue.length-1, retValue.length);
   
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   
  while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }

   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function openAddForm(){

	var bar ="status=no,menubar=no,scrollbars=yes,resizable=no,top=0,left=0,width=" + (screen.availWidth-3)  + " height=" + (screen.availHeight-25);
	window.open('$CONTROLLERURL?Action=ADD$FKEYS','',bar);
	return false;
}

function openLinkedAddForm(caller,para){

	var bar ="status=no,menubar=no,scrollbars=yes,resizable=no,top=0,left=0,width=" + (screen.availWidth-3)  + " height=" + (screen.availHeight-25);
	window.open(caller+"?Action=ADD" + para ,'',bar);
	return false;
}	
		
function openUrl(url){
	var bar ="status=no,menubar=no,scrollbars=yes,resizable=no,top=0,left=0,width=" + (screen.availWidth-3)  + " height=" + (screen.availHeight-25);
	var txt="Attenzione: sono state fatte delle modifiche non ancora salvate. Continuare?";
	var isAdd=false;

	try{

		if (url.indexOf("Action=ADD")>-1) isAdd=true;

		if(isAdd) {
			if (document.formCheck.Changed.value=="-1"){
				if (!(confirm(txt))) return false;
			}
		}
		
	}catch(e){}

	if (curWindow==0){
		curWindow=window.open(url,'',bar);
	}else{
		try{curWindow.location=url;}
		catch(e){curWindow=window.open(url,'',bar);}
	}
	
	try{curWindow.focus();}catch(e){}
	return false;
}	

function openUrlWithMenu(url){
	var bar ="toolbar=yes, status=no,location=no, menubar=yes,scrollbars=yes,resizable=no,top=0,left=0,width=" + (screen.availWidth-3)  + " height=" + (screen.availHeight-100);
	window.open(url,'',bar);
	return false;
}	

function openUrlSize(url,width,height){
	var bar ="status=no,menubar=no,scrollbars=yes,resizable=no,top=200,left=200,width=" + width + " height=" + height ;
	window.open(url,'',bar);
	return false;
}	

function openUrlSizeNoScroll(url,width,height){
	var bar ="status=no,menubar=no,scrollbars=no,resizable=no,top=200,left=200,width=" + width + " height=" + height ;
	w=window.open(url,'',bar);
	return w;
}


function refreshFrames(){
	
	try {
		for (i=0;i<=200;i=i+1) window.frames[i].location=window.frames[i].location;
	}catch(e){}
	
	try {
		for (i=0;i<=200;i=i+1){
			opener.frames[i].location=opener.frames[i].location;
		}
	}catch(e){}


	
	try {
		for (i=0;i<=200;i=i+1){
			opener.parent.frames[i].location=opener.parent.frames[i].location;
		}
	}catch(e){}
	
	try {
		for (i=0;i<=200;i=i+1){
			parent.frames[i].location=parent.frames[i].location;
		}
	}catch(e){}
}


function showContent()

{
var content = ErrMsg;
 if(ie4)
 {  showContentObj=document.all.ErrorMessage; }
 
 if(ns6)
 {  showContentObj=document.getElementById("ErrorMessage"); }
 
 if(ie4||ns6)
 {
  if(showContentObj.innerHTML!=content)
  { showContentObj.innerHTML=content; }
  else
  { showContentObj.innerHTML=""; }
 }

 if(ns4)
 {  
 	document.Errorlayer.document.write(content);
  	document.Errorlayer.document.close();
 }
}


	//abilita il pulsante di salvatagio.
	//da richimare nei campi di input sul keypress
	
	function enableSaveButton(){
		document.formData.Update.value="true";
		document.formCheck.Changed.value="-1";


	}
	
	//limita input a numeri e ,
	function numericInput(eventObj, obj){
		var keyCode
		var str=obj.value
		
		// Check For Browser Type
		if (document.all){keyCode=eventObj.keyCode}
		else{keyCode=eventObj.which}

		if(keyCode==46){if (str.indexOf(",")>0){return false}}

		if((keyCode<48 || keyCode >58)   &&   (keyCode != 46)){return false}
		return true
	}

	
	function strictNumericInput(eventObj, obj){
		var keyCode
		var str=obj.value
		
		// Check For Browser Type
		if (document.all){keyCode=eventObj.keyCode}
		else{keyCode=eventObj.which}

		if((keyCode<48 || keyCode >58)){return false}
		return true
	}
	
        function DecimalNumericInput(eventObj, obj){
		var keyCode
		var str=obj.value
		
		// Check For Browser Type
		if (document.all){keyCode=eventObj.keyCode}
		else{keyCode=eventObj.which}

                //punto
                if(keyCode==46){return true} 

		//virgola
                if(keyCode==44){return true} 

		if((keyCode<48 || keyCode >58)){return false}
		
                return true
	}


	function dateInput(eventObj, obj){
		var keyCode
		var str=obj.value
		
		// Check For Browser Type
		if (document.all){keyCode=eventObj.keyCode}
		else{keyCode=eventObj.which}

		if(keyCode==47){return false}

		if((keyCode<48 || keyCode >58)){return false}
		return true
	}
	
	function dateInputBar(eventObj, obj){
		var keyCode
		var str=obj.value
		
		// Check For Browser Type
		if (document.all){keyCode=eventObj.keyCode}
		else{keyCode=eventObj.which}

		if(keyCode==47){return true}

		if((keyCode<48 || keyCode >58)){return false}
		return true
	}
	
	function sepDate(field){

		 var frmt=new String(field.value);

		 if (frmt.indexOf("/")==-1){
		 	
			if (frmt.length==8){
		 		field.value = frmt.substr(0,2)+ "/" + frmt.substr(2,2)+"/" + frmt.substr(4,4);
			}	
		 }
	}
	
	function advance(current,next,len){
		if (current.value.length==len){
			next.focus();
			next.select();
		}
	}
	
	function advanceDate(current,next,len){
		if (current.value.indexOf("/")==-1){advance(current,next,len-2);}	
		else {advance(current,next,len)};
		
	}

	
	function postOnEnter(eventObj,obj){
		var keyCode
		var str=obj.value
		
		// Check For Browser Type
		if (document.all){keyCode=eventObj.keyCode}
		else{keyCode=eventObj.which}
		
		if(keyCode==13){
			eventObj.keyCode=0;
			document.formData.submit();
		}

	}
	
	function y2k(number) { return (number < 1000) ? number + 1900 : number; }

	
	function chkDate(date){
		try{
			
			
			var day 	= 	parseInt("1"+date.substr(0,2))-100;
			var month	=	parseInt("1"+date.substr(3,2))-100;
			var year	=	parseInt(date.substr(6,4));
			
			return isDate(day,month-1,year);
		}catch(er){return false;}	
	}
	
	
	function chkDateLessToday(date){

		try{
			var day 	= 	parseInt("1"+date.substr(0,2))-100;
			var month	=	parseInt("1"+date.substr(3,2))-100;
			var year	=	parseInt(date.substr(6,4));
			var isValid=isDate(day,month-1,year);
			
			if(!isValid) return false;

			var today = new Date() ;
			var chk=new Date(year,month-1,day);
						
			if(chk>=today) return false
			else return true;

		}catch(er){return false;}
		
	}

  function isDate (day,month,year){ 

    	var today = new Date();
    	var test = null;
    	
    	if (!day) return false;
    	
    	try{var test = new Date(year,month,day);}
    	catch(er){return false;}
		    	
    	if ( (y2k(test.getYear()) == year) &&	(month == test.getMonth()) &&	(day == test.getDate()) ){
			return true;
		}else{
    		return false;
       } 	
		
  }

	function hlme(obj){
	
		var tbl = obj.parentElement.parentElement.parentElement;
	
		var rIdx=obj.parentElement.rowIndex;
		
		if (window.event.ctrlKey){
		
			for (j=0; j < tbl.rows(rIdx).cells.length; j++) {
	
				aClass=tbd.rows(rIdx).cells(j).className;
	
				if (aClass.substr(0,2)=="u_") {aClass=aClass.substr(2,30);}
				
				tbd.rows(rIdx).cells(j).className=aClass;
	
	        }
		
		}else{
			
		    var count=0;
		    for (i=0; i < tbl.rows.length; i++) {
		
				for (j=0; j < tbl.rows(i).cells.length; j++) {
					
					aClass=tbd.rows(i).cells(j).className;
		
					if (aClass.substr(0,2)=="u_") {aClass=aClass.substr(2,30);}
		
					if (i != rIdx){aClass = "u_"+aClass;}
		
					tbd.rows(i).cells(j).className=aClass;
		            count++;
		        }

		    }
		}
	}
	
	